<template>
    <div>
        <div class="crumbs">
            问题描述：<Input type="text" v-model="info.title" ></Input>
        </div>
        <div class="container">
            <quill-editor ref="myTextEditor" v-model="info.solution" :options="editorOption"></quill-editor>
            <el-button class="editor-btn" type="primary" @click="submit">提交</el-button>
        </div>
    </div>
</template>

<script>

    import 'quill/dist/quill.core.css';
    import 'quill/dist/quill.snow.css';
    import 'quill/dist/quill.bubble.css';
    import { quillEditor } from 'vue-quill-editor';
    import util from '../libs/util';

    export default {

        name: 'editor',

        created() {
           this.load_data(this.$route.query.help_id);
        },

        data: function(){
            return {
                info: {},
                editorOption: {
                    placeholder: 'Hello World'
                }
            }
        },

        components: {
            quillEditor
        },

        methods: {

            onEditorChange({ editor, html, text }) {
                this.content = html;
            },

            submit(){
                
                this.$http.post(util.baseURL+"help/updateHelpInfo",this.info,
                    {emulateJSON: true})
                    .then(
                        (response)=>{
                            if(response.data.data) {
                                console.log(this.info);
                              this.$Message.info("更新成功");
                              this.$router.push({path:"/index/helplist"});
                            } else {
                               this.$Message.error("更新失败");
                            }
                        },
                        (error)=>{
                            console.log(error);
                        }
                );
            },

            load_data(id) {
                var body = {id, id};
                console.log(body);
               // 获取服务器数据
               this.$http.post(util.baseURL+"help/getHelpInfo",body,
                    {emulateJSON: true})
                    .then(
                        (response)=>{
                            if(response.data.data) {
                              this.info = response.data.data;
                            } else {
                               //this.$Message.error("暂无问题列表！");
                            }
                        },
                        (error)=>{
                            console.log(error);
                        }
                );
               
            },

        }
    }
</script>
<style scoped>
    .editor-btn{
        margin-top: 20px;
    }
</style>